package com.hg.oa.module.calendar.presenter;

import android.content.Context;
import android.text.Editable;
import android.text.TextUtils;
import android.widget.ArrayAdapter;

import com.hg.oa.R;
import com.hg.oa.common.BasePresenterImpl;
import com.hg.oa.widget.CalendarViewDialog;
import com.rengwuxian.materialedittext.MaterialEditText;
import com.weiwangcn.betterspinner.library.material.MaterialBetterSpinner;

/**
 * Created by fengxiang on 2016/9/14.
 */
public class ApplyPagePressenter extends BasePresenterImpl {


    CalendarViewDialog calendarViewDialog;

    public ApplyPagePressenter(Context context, CalendarViewDialog.OnDateSelectedListener listener) {
        super(context);
        calendarViewDialog = new CalendarViewDialog(context, listener);
    }



    public void showCalendarViewDialog() {
        calendarViewDialog.show();
    }


    public void loadSelectTypeData(MaterialBetterSpinner spinner) {
        String[] strs = new String[]{"项目实施", "售前支持", "研发"};
        ArrayAdapter<String> adapter = new ArrayAdapter<>(
                context, android.R.layout.simple_spinner_dropdown_item
                , strs
        );
        spinner.setAdapter(adapter);
    }

    public void validateWorkTime(Editable s, MaterialEditText edit_worktime){
        String str = s.toString();
        float f = Float.parseFloat(TextUtils.isEmpty(str) ? "0" : str);
        if (f < 0.1 || f > 1) {
            edit_worktime.setErrorColor(context.getResources().getColor(R.color.red));
            edit_worktime.setError("请输入一个介于 0.1 和 1 之间的值");
        }
    }

    /**
     * 设置填写的日报日期
     * @param date
     * @param edit_date
     */
    public void setSelectedDate(String date,MaterialEditText edit_date){
        edit_date.setText(date);
    }
}
